<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/common/taglibs.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<%@ include file="/common/meta.jsp"%>
<title>汪星客 - 个人中心 - 店铺信息管理</title>
</head>
<body>
	<div class="wrap">
		<div class="header_bg">
			<%@ include file="/common/header.jsp"%>
	    </div>
	    <div class="w">
	    	<div class="path box">
	    		<jsp:include page="/common/frame/frame_path.jsp">
            		<jsp:param name="current" value="店铺信息"/>
            	</jsp:include>
	        </div>
	    </div>
	    <div class="main">
	    	<div class="list box">
	        	<div class="pc_left">
            	<jsp:include page="/common/frame/frame_left.jsp">
            		<jsp:param name="checked" value="host"/>
            	</jsp:include>
            	</div>
	            <div class="pc_right">
	                <div class="pc_m fl">
	                	<div class="password">
	                		<form id="frame_host_form" method="post" action="${ctx}/host/save.do">
	                        <div class="info"><p class="font_s">给你的汪星旅店起个名字</p>
								<input class="easyui-validatebox ipt_txt"" name="host.hostName" data-options="required:true, prompt:'给你的“店面”起个名字。'"/>
							</div>
	                        <div class="info"><p class="font_s">地区</p>
		                        <div id="frame_host_form_dist_box">
		                        	<input id="cityId" name="host.cityId"/>
									<input type="hidden" name="host.cityName"/>
									<input type="hidden" name="host.distCode"/>
									<input type="hidden" name="host.distName"/>
									<input type="hidden" name="host.hostArea"/>
								</div>
	                        </div>
	                        <div class="info"><p class="font_s">详细地址</p>
	                        	<input class="easyui-validatebox ipt_txt" name="host.hostAddress" tempVal="" data-options="required:true"/>
	                        </div>
	                        <div class="info"><p class="font_s">旅店介绍</p>
	                        	<textarea name="host.hostDescribe"></textarea>
	                        </div>
	                        <div class="info"><p class="font_s">房屋类型</p>
		                        <select name="host.hostHouseName" class="easyui-combobox" data-options="panelHeight:'auto',editable:false"> 
									<option>高层楼房（带电梯）</option>
									<option>低层楼房（无电梯）</option> 
									<option>平房</option>
									<option>别墅</option>
								</select>
	                        </div>
	                        <div class="info"><p class="font_s">房屋面积</p>
	                        	<select name="host.hostSpaceName" class="easyui-combobox" data-options="panelHeight:'auto', editable:false"> 
									<option>50-100平方米</option>
									<option>100-200平方米</option>
									<option>50平方米以下</option>
									<option>200平方米以上</option>
								</select>
	                        </div>
	                        <!--
	                        <div class="info"><p class="font_s">可同时收养的数量</p>
	                        	<select name="host.hostMaxNum" class="easyui-combobox" data-options="panelHeight:'auto', editable:false"> 
									<option value="1">1只</option>
									<option value="2">2只</option>
									<option value="3">3只</option>
								</select>
	                        </div>
	                        -->
	                        <div class="info"><p class="font_s">您有几年宠物狗饲养经验？</p>
	                        	<input class="easyui-validatebox ipt_txt" name="host.hostExperience" data-options="required:true, validType:['Number','length[1,2]']"/>
	                        </div>
	                        </form>
	                    </div>
	                    <div class="btn"><a href="#" onclick="submitHostInfo(this)" class="easyui-linkbutton tg-btn">提交</a></div>
	                </div>
	            </div>
	            <div class="clear"></div>
			</div>
	    </div>
	    <div class="footer_bg">
	    	<%@ include file="/common/footer.jsp"%>
	    </div>
	</div>
</body>
<script type="text/javascript">
var distCodeIndex = 1;
var distCodeArray = [];
function appendDisSelect(id, pdis) {
	if($("#hostArea").length > 0) {
		$("#hostArea").combobox("destroy");
		$("[name='host.hostArea']").val("");
	}
	$("input[pdis^='" + pdis + "']").combobox("destroy");
	$.getJSON("${ctx}/district/get.do?id=" + id, function(listData) {
		if(listData.length > 0) {
			listData.insert(0, {id:"", disName:"=请选择="});
			var $combo = $("<input/>").attr("pdis", pdis);
			$("#frame_host_form_dist_box").append($combo);
			$combo.combobox({
				valueField:'id',
				textField:'disName',
// 				panelHeight:"auto",
				editable:false,
				data:listData,
				required:true,
				onLoadSuccess:function(data){
					if($.isArray(data) && data.length > 0){
						if(distCodeIndex > 0 && distCodeIndex < distCodeArray.length){
							$(this).combobox("select", distCodeArray[distCodeIndex++]);
						} else {
							$(this).combobox("select", data[0].id);
						}
					}
				},
				onSelect:function(record) {
					if(record.id != "") {
						appendDisSelect(record.id, record.id);
						$("[name='host.distCode']").val(record.disCode + "_" + record.id);
						$("[name='host.distName']").val(record.disName);
					}
				}
			});
		} else {
			$.getJSON("${ctx}/district/getarea.do?id=" + id, function(listData) {
				if(listData.length == 0) return;
				listData.insert(0, {areaName:"=选择商圈="});
				var $combo = $("<input/>").attr("id","hostArea");
				$("#frame_host_form_dist_box").append($combo);
				$combo.combobox({
					valueField:'areaName',
					textField:'areaName',
// 					panelHeight:"auto",
					editable:false,
					data:listData,
					required:true,
					onLoadSuccess:function(data){
						if($.isArray(data) && data.length > 0) {
							var hostArea = $("input[name='host.hostArea']").val();
							for(var i=0;i<data.length;i++) {
								if(hostArea == data[i].areaName) {
									$(this).combobox("select", hostArea);
									hostArea = "";
									break;
								}
							}
							if(hostArea != "" || $("input[name='host.hostArea']").val() == "") {
								$(this).combobox("setValue", data[0].areaName);
							}
						}
					},
					onSelect:function(record) {
						if(record.id != "") {
							$("input[name='host.hostArea']").val(record.areaName);
						} else {
							$("input[name='host.hostArea']").val("");
						}
						//setHostAddress();
					}
				});
			});
		}
	});
}
$.getJSON("${ctx}/district/get.do", function(data) {
	if(data.length == 0) return;
	data.insert(0, {id:"", disName:"=请选择="});
	$("#cityId").combobox({
		valueField:'id',
		textField:'disName',
// 		panelHeight:"auto",
		editable:false,
		data:data,
		required:true,
		onSelect:function(record) {
			$("input[pdis]").combobox("destroy");
			if(record.id != "") {
				appendDisSelect(record.id, record.id);
				$("[name='host.cityName']").val(record.disName);
				//setHostAddress();
			}
		}
	});
});
$('#frame_host_form').form({
	onLoadSuccess:function(host) {
		frame.onLoadForm(this, "host", host);
		//初始化区域选择框
		if(host.distCode != null) {
			distCodeArray = host.distCode.split("_");
			$("input[pdis]").combobox("destroy");
			appendDisSelect(host.cityId, host.cityId);
		}
		
		var hostAddress = $("input[name='host.cityName']").val();
		$("#frame_host_form_dist_box").find("[pdis]").each(function(){
			hostAddress += (" " + $(this).combobox("getText"));
		});
		hostAddress += (" " + $("[name='host.hostArea']").val());
		$("input[name='host.hostAddress']").attr("tempVal", hostAddress);
	}
}).form('load', "${ctx}/host/get.do");

$("input[name='host.hostAddress']").focus(function(){
	var hostAddress = $("input[name='host.cityName']").val();
	if(hostAddress != "") {
		$("#frame_host_form_dist_box [pdis]").each(function(){
			hostAddress += (" " + $(this).combobox("getText"));
		});
		hostAddress += (" " + $("[name='host.hostArea']").val());
	}
	if($(this).val() == "") {
		$(this).val(hostAddress).focus();
	}
});
function submitHostInfo(buttonObj) {
	frame.submitForm("frame_host_form", buttonObj, function(res) {
        if (res.code == 1) {
        	msg.msg("店铺信息保存成功.");
        } else {
        	msg.err(res.msg);
        }
    });
}
</script>
</html>